//
//  CollectionVC.m
//  sensen_ios
//
//  Created by mc on 16/2/29.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "CollectionVC.h"

#import "PostDetailVC.h"
#import "ProductDetailsVC.h"
// 单元格
#import "CartCell.h"
#import "AmountModifyView.h"
#import "CollectionTitleCell.h"
#import "CommentBottomCell.h"
#import "PostPictureCell.h"

#import "CollectionModel.h"
#import "HMSegmentedControl.h"

#import "ProductModel.h" // 商品列表数据
#import "PostModel.h"
#import "ZKTextImgReplaceHandle.h"
#define Margin 13

@interface CollectionVC ()<UITableViewDataSource, UITableViewDelegate>{
    NSArray * aryTitle;  //订单标题
    NSArray * aryStatus; //订单状态
    NSInteger _currentIndex;
    NSInteger _page_no;//页码
    NSInteger _page_size;//页面元素个数
    NSInteger _count;
}

@property (strong, nonatomic)  HMSegmentedControl *segTitle;
@property (strong, nonatomic)  UITableView *tableView;
// 数据
@property (nonatomic, strong) NSMutableArray *itemsAry; // 信息数组，由网络获取
@property (nonatomic, strong) NSMutableArray *selectedItemsAry; // 选中的数组


// 视图
@property (nonatomic, strong) UIView *emptyView; // 没有信息时候的视图
@end


@implementation CollectionVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的收藏";
    self.view.backgroundColor = rgba(239, 239, 244, 1);
    [self createLeftBarButtonItemWithImagename:nil]; // 创建左侧返回按钮
    [self createRightBarButtonItemWithTitle:@"删除"]; // 导航栏右侧按钮
    [self _initViews];
    [self _initTitleView];
    [self _getData];
    _currentIndex = 0;

}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    [self.navigationController setNavigationBarHidden:NO animated:YES];

    
    
    // 设置背景颜色
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:SS_NAVI_BLUE_COLOR] forBarMetrics:UIBarMetricsDefault];
    
    // 隐藏标签栏
    MainTabBarController *main = (MainTabBarController *)self.navigationController.tabBarController;
    [main hideTabBar];
    [self _getData];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    // 显示标签栏
    MainTabBarController *main = (MainTabBarController *)self.navigationController.tabBarController;
    [main showTabBar];
}

#pragma mark -- 创建视图 --
- (void)_initViews{
    self.segTitle = [[HMSegmentedControl alloc] init];
    [self.view addSubview:self.segTitle];
    [self.segTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).offset(0);
        make.left.equalTo(self.view).offset(0);
        make.top.equalTo(self.view).offset(0);
        make.height.equalTo(@(36));
    }];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 36, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 36) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    if (_currentIndex == 1) {
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    self.view.backgroundColor = rgba(237, 238, 239, 1);
    self.tableView.hidden = YES;
    
    //刷新
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(_getData)];
    _tableView.header = header;
    
    // 下拉加载更多
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(_getMoreData)];
    _tableView.footer = footer;
    

    [self _createEmptyView];
    
}

#pragma mark -- 初始化数据 --
- (void)_initTitleView{
    aryTitle = @[@"商品收藏",@"帖子收藏"];//< 0:商品收藏，1:帖子收藏
    aryStatus = @[@0,@1];
    
    self.segTitle.sectionTitles = aryTitle;
    self.segTitle.backgroundColor = [UIColor whiteColor];
    self.segTitle.font = [UIFont boldSystemFontOfSize:14.0];
    self.segTitle.scrollEnabled = YES;
    self.segTitle.textColor =  [UIColor darkGrayColor];//[BoyeTool colorFromHexRGB:@"999999"];
    self.segTitle.selectedTextColor = [BoyeTool colorFromHexRGB:@"ff5657"];
    self.segTitle.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
    self.segTitle.selectionStyle =  HMSegmentedControlSelectionStyleFullWidthStripe;
    self.segTitle.selectionIndicatorHeight = 2;
    self.segTitle.segmentEdgeInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.segTitle.backgroundColor = rgba(247, 247, 247, 1);
    __weak typeof(self) weakSelf = self;
    [self.segTitle setIndexChangeBlock:^(NSInteger index) {
        [weakSelf changeSelect:index animated:YES];

    }];
    UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 35, SCREEN_WIDTH, 1)];
    lbl.backgroundColor = [BoyeTool colorFromHexRGB:@"dbdbdb"];
    
    [self.view addSubview:self.segTitle];
    [self.segTitle addSubview:lbl];
    
   
}

- (void)changeSelect:(NSInteger)intSelect animated:(BOOL)animated{
    [self.selectedItemsAry removeAllObjects];
    [self.segTitle setSelectedSegmentIndex:intSelect animated:animated];
    _currentIndex = intSelect;
    [self cleanChecked];
    self.tableView.hidden = YES;
    [self _getData];
    if (_currentIndex == 1) {
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }


}

- (void)rightAction:(UIButton *)button{
    if (_currentIndex == 0) {
        [self deleteAction:button];
    }else if (_currentIndex == 1){
        [self deleteAction:button];
    }
    
}

#pragma mark - 获取数据
//加载收藏列表
- (void)_getData {
    
   [SVProgressHUD showWithStatus:@"正在加载..." maskType:SVProgressHUDMaskTypeBlack];
    
   //[SVProgressHUD showWithStatus:@"正在加载..."]; // 请求中
    _page_size = 10;
    _page_no = 1;
    NSString * url;
    if (_currentIndex == 0) {
        url = @"BY_Product_getFavorites";
    }else if (_currentIndex == 1){
        url = @"BY_ForumThread_getFavorites";
    }
    [BoyeHttpClient cancelAllOperations];
    
    NSMutableDictionary *  diction = [NSMutableDictionary dictionaryWithCapacity:0];
    UserModel *user = [CommonCache getUserInfo];
    [diction setObject:user.uid forKey:@"uid"];
    [diction setObject:[NSString stringWithFormat:@"%ld", (long)_page_no] forKey:@"page_no"];
    [diction setObject:[NSString stringWithFormat:@"%ld", (long)_page_size] forKey:@"page_size"];
    
    __weak typeof (self) weakSelf = self;
    [BoyeHttpClient post:url apiVerson:100 params:diction success:^(AFHTTPRequestOperation *operation, id result) {
        
        NSLog(@"result = %@", result);
        weakSelf.tableView.hidden = NO;
        if (weakSelf.itemsAry == nil) {
            weakSelf.itemsAry = [NSMutableArray array];
            
        }else{
            [weakSelf.itemsAry removeAllObjects];
        }
        
        NSLog(@"%@", result);
        
       if (![result[@"list"] isKindOfClass:[NSNull class]]) { // 有数据
           
           for (NSDictionary * dic in result[@"list"]) {
               if (_currentIndex == 0) {
                   NSLog(@"%@", dic);
                   CollectionModel * model = [[CollectionModel alloc] initContentWithDic:dic];
                    model.checked = NO;
                   [weakSelf.itemsAry addObject:model];
               }
               
               if (_currentIndex == 1){
                    CollectionModel * model = [[CollectionModel alloc] initContentWithDic:dic];
                    model.checked = NO;
                    [weakSelf.itemsAry addObject:model];
                   
               }
           }
           
           _emptyView.hidden = YES;
           _tableView.hidden = NO;
       }else{
           
            _tableView.hidden = YES;
           _emptyView.hidden = NO;
       }
        
        if (weakSelf.itemsAry.count == [result[@"count"] integerValue]) {
            [_tableView.footer noticeNoMoreData];
        }

        [SVProgressHUD dismiss];
         [_tableView.header endRefreshing]; // 结束刷新
        [weakSelf.tableView reloadData];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [_tableView.header endRefreshing]; // 结束刷新
        [SVProgressHUD showErrorWithStatus:@"请求失败" withDuration:2];
    }];
    
    
}

//获得更多列表信息
- (void)_getMoreData {
    [SVProgressHUD showWithStatus:@"正在加载..."]; // 请求中
    _page_no += 1;
    _page_size = 10;
    NSString * url;
    if (_currentIndex == 0) {
        url = @"BY_Product_getFavorites";
    }else if (_currentIndex == 1){
        url = @"BY_ForumThread_getFavorites";
    }
    NSMutableDictionary *  diction = [NSMutableDictionary dictionaryWithCapacity:0];
    UserModel *user = [CommonCache getUserInfo];
    [diction setObject:user.uid forKey:@"uid"];
    [diction setObject:[NSString stringWithFormat:@"%ld", (long)_page_no] forKey:@"page_no"];
    [diction setObject:[NSString stringWithFormat:@"%ld", (long)_page_size] forKey:@"page_size"];
    __weak typeof (self) weakSelf = self;
    NSLog(@"页码 ＝ %ld", (long)_page_no);
    [BoyeHttpClient post:url apiVerson:100 params:diction success:^(AFHTTPRequestOperation *operation, id result) {
        NSLog(@"result = %@", result);
        _tableView.hidden = NO;

        if (![result[@"list"] isKindOfClass:[NSNull class]]) { // 有数据
            for (NSDictionary * dic in result[@"list"]) {
                if (_currentIndex == 0) {
                    CollectionModel * model = [[CollectionModel alloc] initContentWithDic:dic];
                    model.checked = NO;
                    [weakSelf.itemsAry addObject:model];
                }
                
                if (_currentIndex == 1){
                    CollectionModel * model = [[CollectionModel alloc] initContentWithDic:dic];
                    model.checked = NO;
                    [weakSelf.itemsAry addObject:model];
                }
            }
           
           
        }

        [SVProgressHUD dismiss];
        if (weakSelf.itemsAry.count == [result[@"count"] integerValue]) {
            [_tableView.footer noticeNoMoreData];
        }else{
            [_tableView.footer endRefreshing];
        }

        [weakSelf.tableView reloadData];
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [_tableView.footer endRefreshing];
        [SVProgressHUD showErrorWithStatus:@"请求失败" withDuration:2];
    }];
    
    
}

- (void)deleteAction:(UIButton *)button{
    if (self.selectedItemsAry.count == 0) {
        [SVProgressHUD showOnlyStatus:@"请选择要删除的对象" withDuration:1];
        return;
    }
    
    [SVProgressHUD showWithStatus:@"请求中..."]; // 请求中
   
    NSMutableString * tempString = [NSMutableString stringWithCapacity:1];
    
    
    for (int i = 0; i < self.selectedItemsAry.count; i++) {
        CollectionModel *model = [self.selectedItemsAry objectAtIndex:i];
        if (i == self.selectedItemsAry.count - 1) {
            [tempString appendString:[NSString stringWithFormat:@"%@", model.favorite_id]];
            
        }else{
            [tempString appendString:[NSString stringWithFormat:@"%@,", model.favorite_id]];
        }
       
    }
    
    
    
    NSMutableDictionary *  diction = [NSMutableDictionary dictionaryWithCapacity:0];
    [diction setObject:tempString forKey:@"favorite_id"];

    UserModel *user = [CommonCache getUserInfo];
    [diction setObject:user.uid forKey:@"uid"];
    
    if (_currentIndex == 0) {
        [diction setObject:@"1" forKey:@"type"];
    }else if (_currentIndex == 1){
        [diction setObject:@"2" forKey:@"type"];
    }
    [BoyeHttpClient post:@"BY_Favorites_cancel" apiVerson:100 params:diction success:^(AFHTTPRequestOperation *operation, id result) {
        NSLog(@"%@", result);
        [SVProgressHUD showSuccessWithStatus:@"删除成功" withDuration:2];
        [self _getData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求失败" withDuration:2];
    }];

    
}



// 选中数组 懒加载
- (NSMutableArray *)selectedItemsAry {
    if (_selectedItemsAry == nil) {
        self.selectedItemsAry = [[NSMutableArray alloc] init];
    }
    
    return _selectedItemsAry;
}


/// 没有信息时候的视图
- (void)_createEmptyView {
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat width = SCREEN_WIDTH * 0.5;
    CGFloat height = width;
    _emptyView = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    [self.view addSubview:_emptyView];
    
    y = 0;
    width = _emptyView.width * 0.6;
    height = width;
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    imgView.image = [UIImage imageNamed:@"购物车为空"];
    [_emptyView addSubview:imgView];
    imgView.center = CGPointMake(_emptyView.center.x, imgView.center.y);
    
    x = 0;
    y = imgView.bottom + 5;
    width = _emptyView.width;
    height = 20;
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    label.font = FONT(18);
    label.text = @"您的收藏空空如也";
    label.textColor = SS_NAVI_ORANGE_LIGHT_COLOR;
    label.textAlignment = NSTextAlignmentCenter;
    [_emptyView addSubview:label];
    _emptyView.center = self.view.center;
    _emptyView.hidden = YES;
}

#pragma mark - UITableViewDataSource UITableViewDelegate
// 设置组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (_currentIndex == 0) {
        return 1;
    }
    
    else if (_currentIndex == 1){
        return _itemsAry.count;
    }else{
        return _itemsAry.count;
    }
    
}
// 设置行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (_currentIndex == 0) {
        return [_itemsAry  count];
    }
    
    else if (_currentIndex == 1){
        CollectionModel * model = [_itemsAry objectAtIndex:section];
        if (model.img.count > 0) {
            return 4;
        }else{
            return 3;

        }
    }else{
        return 3;
    }
    
    
}
// 设置单元格属性
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (_currentIndex == 0) {
        
        CollectionModel * model = [_itemsAry objectAtIndex:indexPath.row];
        static NSString * cellIdentifier = @"CartCell";
        CartCell *cell = (CartCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell ==nil) {
            cell = [[CartCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.amountModifyView.hidden = YES;
        cell.skuLabel.hidden = YES;
        cell.nameLabel.height = 40;
        cell.nameLabel.numberOfLines = 2;
        [cell.iconView setImageURLStr:model.img_url placeholder:DEFAULT_IMAGE];
        cell.selectButton.selected = model.checked;
        [cell.selectButton addTarget:self action:@selector(chooseSingle:event:) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    }
    
    else  {
        
        if (indexPath.row == 0) {
            CollectionModel * model = [_itemsAry  objectAtIndex:indexPath.section];
            CollectionTitleCell *cell =[CollectionTitleCell cellWithTableView:tableView];
            cell.isHaveBtn = YES;
            cell.model = model;
            cell.selectButton.selected = model.checked;
            [cell.selectButton addTarget:self action:@selector(chooseSingle:event:) forControlEvents:UIControlEventTouchUpInside];
            return cell;
        }else if(indexPath.row == 1){
            CollectionModel * model = [_itemsAry  objectAtIndex:indexPath.section];
            static NSString * cellIdentifier = @"CommentCell2";
            UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
            if (cell ==nil) {
                cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
            }
            
            for (UIView *view in cell.contentView.subviews) {
                [view removeFromSuperview];
            }
            cell.backgroundColor = [UIColor whiteColor];
            NSString * string =  [NSString stringWithFormat:@"原帖：%@", model.subject];
            CGFloat number = [ZKTextImgReplaceHandle getImgTextHeightWithText:string regex:nil size:CGSizeMake(SCREEN_WIDTH - 26, 10000) fontSize:16];
            UILabel * lable = [[UILabel alloc] initWithFrame:CGRectMake(13, 7, SCREEN_WIDTH - 26, number)];
            [cell.contentView addSubview:lable];
            lable.textColor = [UIColor darkGrayColor];
            lable.font = FONT(16);
            lable.numberOfLines = 0;
            NSMutableAttributedString *attr = [ZKTextImgReplaceHandle handleText:string withRegex:nil];
            if (attr) {
                lable.attributedText = attr;
            } else {
                lable.text = string;
            }

            
            return cell;
        }else{
            CollectionModel * model = [_itemsAry  objectAtIndex:indexPath.section];
            
            
            
            if (model.img.count > 0) {
               
                if (indexPath.row == 2) {
                   
                    PostPictureCell *cell = [PostPictureCell cellWithTableView:tableView];
                    PostModel * postModel = [[PostModel alloc] init];
                    postModel.imgAry = model.img;
                    cell.postModel = postModel;
                    return cell;
                    
                }else{
                    CommentBottomCell *cell = [CommentBottomCell cellWithTableView:tableView];
                    PostModel * postModel = [[PostModel alloc] init];
                    postModel.likes = model.likes;
                    postModel.replies = model.replies;
                    cell.postModel = postModel;
                    return cell;
                }
                
                
            }else{
                CommentBottomCell *cell = [CommentBottomCell cellWithTableView:tableView];
                PostModel * postModel = [[PostModel alloc] init];
                postModel.likes = model.likes;
                postModel.replies = model.replies;
                cell.postModel = postModel;
                return cell;

            }
            
        }
        
    }
}

// 设置单元格行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (_currentIndex == 0) {
        return 80;
        
    }
    
    else if (_currentIndex == 1){
        
        if (indexPath.row == 0) {
            return 48;
        }else if(indexPath.row == 1){
            CollectionModel * model = [_itemsAry  objectAtIndex:indexPath.section];
            NSString * string =  [NSString stringWithFormat:@"原帖：%@", model.subject];
            //CGFloat  height = [string  getBoundingRectOfStringSize:CGSizeMake(SCREEN_WIDTH - 26, 10000) font:13].size.height;
            CGFloat  height = [ZKTextImgReplaceHandle getImgTextHeightWithText:string regex:nil size:CGSizeMake(SCREEN_WIDTH - 26, 10000) fontSize:16];
            return height + 14;
        }else{
            CollectionModel * model = [_itemsAry  objectAtIndex:indexPath.section];
            if (model.img.count > 0) {
                if (indexPath.row == 2) {
                    
                    CGFloat width = (SCREEN_WIDTH - Margin * 4) / 3;
                    CGFloat y = Margin * ((model.img.count - 1) / 3) + width * ((model.img.count - 1) / 3 + 1);
                    return y + 5;

                    
                }else{
                    return 30;
                }
            }else{
                 return 30;
            }
    
        }
    }else{
        return 40;
    }
    
}
// 设置组头高
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 5;
}




// 单元格点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];// 取消选中阴影
    
    if (_currentIndex == 0) {
        
        
        CollectionModel * model = [_itemsAry objectAtIndex:indexPath.row];
        ProductDetailsVC *vc = [[ProductDetailsVC alloc] init];
        vc.pid = model.pid;
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    else if (_currentIndex == 1){
    
        CollectionModel * postModel = [_itemsAry objectAtIndex:indexPath.section];
        
        if ([postModel.status integerValue] == 1) {
            
            PostDetailVC * vc = [[PostDetailVC alloc] init];
            vc.tid = postModel.tid;
            vc.fid = postModel.fid;
            [self.navigationController pushViewController:vc animated:YES];
            
        }else{
            
             [SVProgressHUD showOnlyStatus:@"帖子已被删除" withDuration:1];
            
            
        }
        
        
        
    }
    
    
}

#pragma mark 遍历点击的 那个组
-(BOOL)isSectionGroupAllSelected:(NSIndexPath*)indexPath{
    NSMutableArray * array = [_itemsAry objectAtIndex:indexPath.section];
    for (CollectionModel * model in array) {
        if (!model.checked) {
            return NO;
        }
        
    }
    return YES;
}




#pragma mark 清空所有选中状态
-(void)cleanChecked{
    //所有单元 cell按钮不选中
    for (CollectionModel * model in _itemsAry) {
        model.checked = NO;
    }
    [self.selectedItemsAry removeAllObjects]; //删除所有已选中的数据模型
    [self.tableView reloadData];
}





#pragma mark 选择单个单元事件
-(void)chooseSingle:(UIButton*)btn event:(UIEvent*)event{
    btn.selected = !btn.selected;
    UITouch * touch = [[event allTouches] anyObject];
    CGPoint point = [touch locationInView:self.tableView];
    NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:point];
    
    CollectionModel * productsModel;
    if (_currentIndex == 0) {
        productsModel = [_itemsAry objectAtIndex:indexPath.row];
    }else if(_currentIndex == 1){
        productsModel = [_itemsAry objectAtIndex:indexPath.section];
    }
 
    if (!btn.selected) {
        productsModel.checked = NO; //单个cell不选中
    }else{
        productsModel.checked = YES;//单个cell 选中
    }
    
    
    //获取 选中的 数据模型
    [self getDataFromArray];
    [self.tableView reloadData];
    
}


#pragma mark  遍历所有数据模型 存储选中的 数据模型
- (void)getDataFromArray{
    NSMutableArray * tempArray = [NSMutableArray array];
    for (CollectionModel * model in _itemsAry) {
        if (model.checked) {//选中并且没有失效
            [tempArray  addObject:model];
            
        }
    }
    self.selectedItemsAry = tempArray; //选中的商品数
}

#pragma mark 分割线距离左边距离
-(void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
